home *** CD-ROM | disk | FTP | other *** search
- /* Copyright 1986 Cornell University */
-
- #include <em.h>
-
- #include <3270.h> /* external variables & constants */
- #include <cntldefs.h>
- #include <tftp.h>
- #include <resdefs.h>
-
- #include <rcodes.h>
- #include <h19.h>
-
- #include "::3270XCMD:TNdrvr.h"
-
-
-
- /* Here follows a slew of Hypercard interface routines;
- all of the routines must save and restore A5 since the calls come from
- another MF application heap through the TNdrvr */
-
- /* MPW uses d0/d1/a0/a1 as scratch so we must preserve Aztec scratch regs */
-
- #asm
-
- mpwcregs reg d3/a2
-
- #endasm
-
- extern unsigned long getmyA5();
-
-
- OSErr tnopen()
- {
- unsigned long oldA5;
- OSErr retval = 0;
-
- oldA5 = getmyA5();
- #asm
- movem.l mpwcregs,-(a7)
- #endasm
-
- if (!keydp->hycactive) {
- keydp->hycactive = TRUE;
- }
- else
- retval = HTNR_ACTIVE;
-
- setA5(oldA5);
- #asm
- movem.l (a7)+,mpwcregs
- #endasm
- return(retval);
- }
-
-
- /* open a connection with a host
- failure codes: 1 = already connected
- 2 = can't resolve name
- 3 = invalid address
- 4 = can't reach host
- */
-
- OSErr tnconnect(hoststrp)
- char * hoststrp;
- {
- unsigned long oldA5;
- OSErr retval = 0;
- OSErr connalready = FALSE;
- OSErr connfail = FALSE;
-
- oldA5 = getmyA5();
- #asm
- movem.l mpwcregs,-(a7)
- #endasm
- if (!keydp->hycactive)
- retval = HTNR_ACTIVE;
- else if (!keydp->connopen) {
- if (!resolve_name(hoststrp, &keydp->fhost)) {
- if ((keydp->fhost.u.addr == 0L) || (keydp->fhost.u.addr == -1L) ) {
- retval = HTNR_ADDR;
- }
- else {
- /* make hhostname reflect the hostname */
- if (keydp->hhostname != NULL)
- DisposHandle(keydp->hhostname);
- keydp->hhostname = NewHandle((long) strlen(hoststrp));
- strcpy(*keydp->hhostname, hoststrp);
- ctop(*keydp->hhostname);
-
- keydp->hycconnwait = TRUE;
- /* makeconn();
- check keydp->hycconnwait in main() loop instead
- since MacTCP sync business is uncool...
- */
- }
- }
- else {
- retval = HTNR_NAME;
- }
-
- }
- else
- retval = HTNR_OPEN;
-
- setA5(oldA5);
- #asm
- movem.l (a7)+,mpwcregs
- #endasm
- return(retval);
- }
-
-
- /* close the current connection */
-
- OSErr tnclose()
- {
- unsigned long oldA5;
- OSErr retval = 0;
-
- oldA5 = getmyA5();
- #asm
- movem.l mpwcregs,-(a7)
- #endasm
-
- if (!keydp->hycactive)
- retval = HTNR_ACTIVE;
- else if (!keydp->connopen)
- retval = HTNR_OPEN;
- else {
- tcp_close();
- }
-
- setA5(oldA5);
- #asm
- movem.l (a7)+,mpwcregs
- #endasm
- return(retval);
- }
-
-
- /* the 3270 driver client no longer requires our services */
-
- OSErr tnquit()
- {
- unsigned long oldA5;
-
- oldA5 = getmyA5();
- #asm
- movem.l mpwcregs,-(a7)
- #endasm
-
- keydp->hycactive = FALSE;
- keydp->userquit = TRUE;
- tcp_close();
-
- cu_exit(0);
-
- setA5(oldA5);
- #asm
- movem.l (a7)+,mpwcregs
- #endasm
- return(0);
- }
-
-
- /* put a string into the 3270 buffer; TAB = field Tab, CR = Enter */
-
- OSErr tnsendstr(sendstrp)
- char * sendstrp;
- {
- OSErr retval = 0;
- unsigned long oldA5;
- struct token atoke;
- struct token tabtoke;
- struct token entertoke;
-
- oldA5 = getmyA5();
- #asm
- movem.l mpwcregs,-(a7)
- #endasm
-
- atoke.class = RSLT_ASCI;
- tabtoke.class = RSLT_MVCR;
- tabtoke.entry = TAB_FWD;
- entertoke.class = RSLT_PFKY;
- entertoke.entry = ENTER;
-
- if (!keydp->hycactive)
- retval = HTNR_ACTIVE;
- else if (!keydp->connopen)
- retval = HTNR_OPEN;
- else {
- /* interpret the string */
- while (atoke.entry = *sendstrp++) {
- #ifdef TRANSLATE
- /* Peter Bosanko prefers no translation for the interface */
- if (atoke.entry == CR) {
- /* do an Enter when we see a CR */
- (*dotoken)(&entertoke);
- }
- else if (atoke.entry == TAB) {
- /* do a field TAB */
- (*dotoken)(&tabtoke);
- }
- else
- #endif
- putaction(RSLT_ASCI, atoke.entry);
- }
- }
-
- setA5(oldA5);
- #asm
- movem.l (a7)+,mpwcregs
- #endasm
- return(retval);
- }
-
-
- /* execute a tn3270 command token encoded in two strings */
-
- OSErr tnsendcmd(class, entry)
- char * class;
- char * entry;
- {
- OSErr retval = 0;
- unsigned long oldA5;
- struct token atoke;
-
- oldA5 = getmyA5();
- #asm
- movem.l mpwcregs,-(a7)
- #endasm
-
- if (!keydp->hycactive)
- retval = HTNR_ACTIVE;
- else if (!keydp->connopen)
- retval = HTNR_OPEN;
- else {
- #ifndef VALIDATE
- /* no validation is performed on the tokens we're handed ... */
- putaction(*class, *entry);
- #else
- atoke.class = *class;
- atoke.entry = *entry;
- switch (*class) {
- case ' ': {
- /* ascii class */
- atoke.entry = *entry;
- putaction(atoke.class, atoke.entry);
- break;
- }
- case 'A': {
- /* local action class */
- if (valaction(*entry)) {
- atoke.entry = *entry;
- putaction(atoke.class, atoke.entry);
- }
- else
- retval = HTNR_ENTRY;
- break;
- }
- case 'P': {
- /* PF key class */
- if ((atoke.entry = hycmappfkey(entry)) != 0) {
- (*dotoken)(&atoke);
- }
- else
- retval = HTNR_ENTRY;
- break;
- }
- case 'M': {
- /* cursor motion class */
- if (valcursor(*entry)) {
- atoke.entry = *entry;
- (*dotoken)(&atoke);
- }
- else
- retval = HTNR_ENTRY;
- break;
- }
- case 'X': {
- /* move to x coord class */
- atoke.entry = atoi(class);
- if (atoke.entry >= 80)
- retval = HTNR_ENTRY;
- else
- (*dotoken)(&atoke);
- break;
- }
- case 'Y': {
- /* move to y coord class */
- atoke.entry = atoi(class);
- if (atoke.entry >= 24)
- retval = HTNR_ENTRY;
- else
- (*dotoken)(&atoke);
- break;
- }
- default: {
- retval = HTNR_CLASS;
- break;
- }
- }
- #endif
- }
-
- setA5(oldA5);
- #asm
- movem.l (a7)+,mpwcregs
- #endasm
- return(retval);
- }
-
-
- /* return the tn3270 status */
-
- OSErr tnstatus(bufptr)
- char * bufptr;
- {
- unsigned long oldA5;
- long scrp;
- OSErr retval = 0;
-
- oldA5 = getmyA5();
- #asm
- movem.l mpwcregs,-(a7)
- #endasm
-
- bufptr = NULL;
-
- if (!keydp->hycactive)
- retval = HTNR_ACTIVE;
- else {
- if (keydp->hycnewdata) {
- retval = HTNS_NEWDATA;
- keydp->hycnewdata = FALSE;
- }
- else if (keydp->hycconnwait) {
- retval = HTNS_WAITCONN;
- }
- else if (nnrup) {
- retval = HTNS_WAITNET;
- }
- else if (keydp->event_reg & KYBD_LOCK) {
- retval = HTNS_KBDLOCK;
- }
- else if (!keydp->connopen) {
- retval = HTNR_OPEN;
- }
- else
- /* retval = HTNS_RUNNING; */
- retval = screenstate();
- }
-
- setA5(oldA5);
- #asm
- movem.l (a7)+,mpwcregs
- #endasm
- return(retval);
- }
-
-
- /* draw the tn3270 screen into a grafport */
-
- OSErr tndraw(qdport)
- GrafPtr qdport;
- {
- OSErr retval;
- unsigned long oldA5;
-
- oldA5 = getmyA5();
- #asm
- movem.l mpwcregs,-(a7)
- #endasm
-
- if (!keydp->hycactive)
- retval = HTNR_ACTIVE;
- else if (!keydp->connopen)
- retval = HTNR_OPEN;
- else {
- ;
- }
-
- setA5(oldA5);
- #asm
- movem.l (a7)+,mpwcregs
- #endasm
- return(retval);
- }
-
-
- hyc_init()
- {
- ParamBlkRec drvpb;
- long * arg;
- struct storage tndarr;
-
- drvpb.ioNamePtr = "\P.TNdrvr";
- drvpb.u.iop.ioPermssn = fsCurPerm;
- PBOpen(&drvpb, (Boolean) FALSE);
- if (drvpb.ioResult) {
- return(-1);
- }
-
- drvpb.u.cp.csCode = HTN_INIT;
-
- /* set up arguments in array */
- tndarr.tnopen = tnopen;
- tndarr.tnconnect = tnconnect;
- tndarr.tnstatus = tnstatus;
- tndarr.tnclose = tnclose;
- tndarr.tnquit = tnquit;
- tndarr.tnsendstr = tnsendstr;
- tndarr.tnsendcmd = tnsendcmd;
- tndarr.tndraw = tndraw;
-
- tndarr.tnscreen = scr_map;
- tndarr.tncursor = &cursor_ptr;
- tndarr.tnfield = ¤t_attr;
-
- arg = &drvpb.u.cp.csParam.diskBuff;
- /* point at first parameter */
- *arg = (long *) &tndarr;
-
- PBControl(&drvpb, (Boolean) FALSE);
- if (drvpb.ioResult)
- return(-1);
-
- }
-
- hycinform()
- {
- keydp->hycnewdata = TRUE;
- }
-
-
- /* check to see if MORE has appeared on the screen to indicate holding */
-
- screenstate()
- {
- if (!strncmp(&scr_map[1900], "RUNN", 4)) {
- return(HTNS_RUNNING); /* == 0 */
- }
- else if (!strncmp(&scr_map[1900], "MORE", 4)) {
- return(HTNS_MORE);
- }
- else if (!strncmp(&scr_map[1900], "VM R", 4)) {
- return(HTNS_VMREAD);
- }
- else if (!strncmp(&scr_map[1900], "CP R", 4)) {
- return(HTNS_CP);
- }
- else if (!strncmp(&scr_map[1900], "HOLD", 4)) {
- return(HTNS_HOLDING);
- }
- else
- return(HTNS_RUNNING);
- }
-
-
- /* return TRUE if valid action entry */
-
- valaction(thechar)
- char thechar;
- {
- switch (thechar) {
- case 'I':
- case 'D':
- case 'E':
- case 'X':
- case 'B':
- case 'R':
- return(TRUE);
- default:
- return(FALSE);
- }
- }
-
- valcursor(thechar)
- char thechar;
- {
- switch (thechar) {
- case 'L':
- case 'D':
- case 'U':
- case 'R':
- case '0':
- case '>':
- case '<':
- case 'N':
- return(TRUE);
- default:
- return(FALSE);
- }
- }
-
- hycmappfkey(entry)
- char * entry;
- {
- int val;
-
- if (*entry >= '0' && *entry <= '9') {
- /* probably numeric */
- val = atoi(entry);
- if (val > 0 && val <= 36) {
- return(val);
- }
- }
- else {
- /* map characters to weird integer values */
- switch (*entry) {
- case 'a': {
- return(PA1);
- }
- case 'b': {
- return(PA2);
- }
- case 'c': {
- return(PA3);
- }
- case 'C': {
- return(CLEAR);
- }
- case 'E': {
- return(ENTER);
- }
- }
- }
- return(0);
- }
-